package com.example.streamconsumer.highlevel;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.stereotype.Component;

/**
 * @Author: lihui
 * @Date: 2022-03-23 10:32
 * @Description:
 */
@Component
@EnableBinding(MyProcessor.class)
public class SourceMessageConsumer {

    @Autowired
    private SmsAndEmailMessageProducer smsAndEmailMessageProducer;

    @StreamListener(MyProcessor.SOURCE_MESSAGE)
    public void receive(String sourceMessage){
        System.out.println("原始消息接收成功，source message = " + sourceMessage);

        smsAndEmailMessageProducer.sendSms(sourceMessage.split("\\|")[0]);

        smsAndEmailMessageProducer.sendEmail(sourceMessage.split("\\|")[1]);
    }

}
